package com.example.testhooter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;

import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class SubCategoryActivity extends Activity implements
		View.OnClickListener {

	static final String SUB_CAT_ID = "sub_cat_id";
	static final String SUB_CAT_NAME = "sub_cat_name";
	static final String TEST_NAME = "test_name";
	ListView cat_list;
	BindSubCategoryData adapter = null;
	List<HashMap<String, String>> subCategoryDataCollection;
	TextView cat_name;
	Button back_btn;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_subcategory);

		Bundle cat_bundle = this.getIntent().getExtras();

		cat_name = (TextView) findViewById(R.id.cat_name);
		back_btn = (Button) findViewById(R.id.back_cat_btn);
		back_btn.setOnClickListener(this);
		cat_name.setText(cat_bundle.getString("cat_name").toString());

		subCategoryDataCollection = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = null;
		map = new HashMap<String, String>();
		map.put(SUB_CAT_ID, "1");
		map.put(SUB_CAT_NAME, "ABC");
		map.put(TEST_NAME, "SAMPLE 1");
		subCategoryDataCollection.add(map);
		map = new HashMap<String, String>();
		map.put(SUB_CAT_ID, "2");
		map.put(SUB_CAT_NAME, "DEF");
		map.put(TEST_NAME, "SAMPLE 2");
		subCategoryDataCollection.add(map);

		BindSubCategoryData bindingData = new BindSubCategoryData(this,
				subCategoryDataCollection);

		cat_list = (ListView) findViewById(R.id.list);

		cat_list.setAdapter(bindingData);

		cat_list.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				Intent i = new Intent();
				i.setClass(SubCategoryActivity.this, TestActivity.class);

				// parameters
				i.putExtra("position", String.valueOf(position + 1));

				i.putExtra("sub_cat_id", subCategoryDataCollection
						.get(position).get(SUB_CAT_ID));
				i.putExtra("sub_cat_name",
						subCategoryDataCollection.get(position).get(
								SUB_CAT_NAME));
				i.putExtra("test_name", subCategoryDataCollection.get(position)
						.get(TEST_NAME));

				startActivity(i);
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_cat_btn:
			Log.v("back bnt", "backbtn");
			super.onBackPressed();
			break;
		}

	}

}
